package com.prothink.controller.statistics;


import com.prothink.entity.CourseLikes;
import com.prothink.service.CourseLikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *课程点赞量控制层
 * @Date 2022 11 24
 */
@CrossOrigin
@Controller
@RequestMapping("CourseLikes")
public class CourseLikesController {
    @Autowired
    private CourseLikesService courseLikesService;

    /**
     * 获取全部被点赞过的课程
     * @param courseLikes 课程点赞实体类
     * @return 所有被点赞过的课程
     */
    @ResponseBody
    @RequestMapping("/getCourseLikes")
    public List getCourseLikes(CourseLikes courseLikes){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            courseLikes.setLikeTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return courseLikesService.getCourseLike(courseLikes);
    }

    /**
     * 添加被点赞的课程信息
     * @param courseLikes 课程点赞量实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/addCourseLikes")
    public Integer addCourseLikes(CourseLikes courseLikes){
        return courseLikesService.addCourseLike(courseLikes);
    }
}
